package Presentation;

import java.awt.Dimension;
import java.awt.Window;
import java.awt.dnd.DragGestureEvent;
import java.awt.dnd.DragGestureListener;
import java.awt.dnd.DragSource;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.BorderFactory;
import javax.swing.JPanel;


import solitaire.application.Usine;

import Controlor.CSabot;
import Controlor.CTasDeCarteAlternee;
import Listener.MyDragSourceListener;
import Listener.MyDragSourceMotionListener;
import Listener.MyGestureListener;
import Listener.RetournerTasListener;
import Listener.SabotRetournerCarteListener;

public class PSabot extends JPanel {

	private static final long serialVersionUID = 1L;
	
	private PTasDeCartes visibles;
	private PTasDeCartes cachees;
	private CSabot controller;
	private Usine usine;
	
	private boolean enableRetournerTas = false;
	private boolean enableRetournerCarte = true;
	
	
	private SabotRetournerCarteListener carteListener;
	private RetournerTasListener tasListener;

	//DnD
	protected MyGestureListener gestureListener;

	protected DragSource dragSource = null;
	
	protected MyDragSourceListener dsListener = null;
	
	protected MyDragSourceMotionListener dsmListener = null;
	
	protected CTasDeCarteAlternee selected = null;
	
	protected Window dragCarrier = null;
	
	protected DragGestureEvent initialEvent;
	
	public PSabot(CSabot csabot,PTasDeCartes cachees,PTasDeCartes visibles){
		controller = csabot;
		this.visibles = visibles;
		this.cachees = cachees;
		this.visibles.align = PTasDeCartes.NON;
		this.visibles.align = PTasDeCartes.NON;
		this.visibles.setMinimumSize(new Dimension(500,200));
		cachees.setBorder(BorderFactory.createLoweredBevelBorder());
		cachees.addMouseListener(carteListener);
		
		add(cachees);
		add(visibles);
		setVisible(true);
	}
	
	public void activerTournerCarte(boolean b){
		enableRetournerCarte = b;
		if(enableRetournerCarte) {
			cachees.addMouseListener(carteListener);
			cachees.removeMouseListener(tasListener);
		} else {
			cachees.removeMouseListener(carteListener);
		}	
	}
	
	public void activerRetournerTas(boolean b){
		enableRetournerTas = b;		
		if(enableRetournerTas) {
			cachees.removeMouseListener(carteListener);
			cachees.addMouseListener(tasListener);
		} else {
			cachees.removeMouseListener(tasListener);
		}	
	}

	public void setLevelDuJeu(int level){
		if(level == 1){
			visibles.setAlignmentX(PTasDeCartes.NON);
		}else if (level == 2){
			visibles.setAlignmentX(PTasDeCartes.HORIZONTALx3);
		}
	}

}
